package com.cx330;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;

public class Example73 {
    public static void main(String[] args) {
        try (
                // 从UTF8的文件种读取内容
                FileReader fr = new FileReader("D:\\UTF8.txt", Charset.forName("UTF-8"));
                // 写内容到GBK的文件中
                FileWriter fw = new FileWriter("D:\\GBK.txt", Charset.forName("GBK"));
        ) {
            int len;
            char[] data = new char[10];
            while ((len = fr.read(data)) != -1) {
                fw.write(data, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
